﻿using VSTalk.Engine.ViewModel;
using VSTalk.Engine.ViewModel.Messenger;
using VSTalk.Model;

namespace VSTalk.Engine.Core.EnvironmentManagers.UI
{
    public class WindowManager : IWindowManager
    {
        private readonly IEnvWindowsManager _envWindowsManager;
        private readonly IHostedControls _hostedControls;
        private readonly IResourceStore _resourceStore;
        private readonly IThemeManager _themeManager;

        public WindowManager(IEnvWindowsManager envWindowsManager, IHostedControls hostedControls, IResourceStore resourceStore, IThemeManager themeManager)
        {
            _envWindowsManager = envWindowsManager;
            _hostedControls = hostedControls;
            _resourceStore = resourceStore;
            _themeManager = themeManager;
        }

        public IThemeManager ThemeManager
        {
            get { return _themeManager; }
        }

        public IEnvWindowsManager EnvWindowsManager
        {
            get { return _envWindowsManager; }
        }

        public IHostedControls HostedControls
        {
            get { return _hostedControls; }
        }

        public IResourceStore ResourceStore
        {
            get { return _resourceStore; }
        }

        public void ShowMainWindow()
        {
            var control = HostedControls.GetControl<MainViewModel>();
            EnvWindowsManager.ShowNestedWindow(control);
        }

        public void ShowChatWindow(Interlocutor interlocutor)
        {
            var control = HostedControls.GetControl<ChatFrameViewModel>();
            EnvWindowsManager.ShowNestedWindow(control);
            var context = HostedControls.GetContext<ChatFrameViewModel>();
            context.AttachEntity(interlocutor);
        }

        public void ShowChatWindow(Room room)
        {
            var control = HostedControls.GetControl<ChatFrameViewModel>();
            EnvWindowsManager.ShowNestedWindow(control);
            var context = HostedControls.GetContext<ChatFrameViewModel>();
            context.AttachEntity(room);
        }
    }
}